package com.yoga.admin.api.web;

import com.yoga.admin.api.annotation.LoginUser;
import com.yoga.common.appexception.AppException;
import com.yoga.common.appexception.YogaResult;
import com.yoga.common.bo.TeacherBO;
import com.yoga.common.bo.YogaAdminBO;
import com.yoga.common.page.PageBO;
import com.yoga.common.qto.TeacherQTO;
import com.yoga.manager.admin.AdminTeacherManager;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by hdx on 2020/10/20.
 */
@RestController
@RequestMapping("${basePath}")
public class AdminTeacherController {

    @Resource
    private AdminTeacherManager teacherManager;

    @PostMapping("/teacher/addData")
    public YogaResult<TeacherBO> addData(@LoginUser YogaAdminBO adminBO, @RequestBody TeacherBO teacherBO) throws AppException{
        TeacherBO result = teacherManager.addData(teacherBO);

        return new YogaResult<>(result);
    }

    @PostMapping("/teacher/updateData")
    public YogaResult<Boolean> updateData(@LoginUser YogaAdminBO adminBO, @RequestBody TeacherBO teacherBO) throws AppException{
        Boolean result = teacherManager.updateData(teacherBO);

        return new YogaResult<>(result);
    }

    @GetMapping("/teacher/deleteData")
    public YogaResult<Boolean> deleteData(@LoginUser YogaAdminBO adminBO, Long teacherId) throws AppException {
        Boolean result = teacherManager.deleteData(teacherId);
        return new YogaResult<>(result);
    }

    @PostMapping("/teacher/findForPage")
    public YogaResult<PageBO<TeacherBO>> findForPage(@LoginUser YogaAdminBO adminBO, @RequestBody TeacherQTO teacherQTO) throws AppException {
        PageBO<TeacherBO> result = teacherManager.findForPage(teacherQTO);
        return new YogaResult<>(result);
    }




}
